<?php
    header('Content-Type: text/html; charset=utf8'); 

require_once 'Dsql.php';
    
    $aphoId = isset($_GET['aphoId'])?$_GET['aphoId']*1:"0";
    $none = isset($_GET['none'])?$_GET['none']*1:"0";
    
    $db = new Dsql("mysql-88.ukraine.com.ua", "barthez_ai", "x9gedv4w");
    $db->selectDb('barthez_ai');

    $db->selectCharset('UTF8');
    
    
    
    $qs = "SELECT * from `byone` WHERE autorId=$aphoId AND aphorismId <> $none order by rand() LIMIT 1";

    $result = $db->createQuery($qs)
                 ->getResult();
    
    
    if(isset($result[0])){
        print json_encode($result[0]);
    }else{
        $qs = "SELECT * from `byone` WHERE autorId=$aphoId order by rand() LIMIT 1";

        $result = $db->createQuery($qs)
                 ->getResult();
        
        print json_encode($result[0]);
        
    }
    
    
    
    die;
    
    
    
    
?>
